﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace WrWpf
{
    internal static class SharedDictionaryManager
    {
        public const string CalendarDayStyle = "Controls/themes/CalendarDayStyle.xaml";

        private static Dictionary<string, ResourceDictionary> _sharedDictionaries = null;

        /// <summary>
        /// Gets the resource dictionary.
        /// </summary>
        /// <param name="uriString">The URI string.</param>
        /// <returns></returns>
        public static ResourceDictionary GetResourceDictionary(string uriString)
        {
            if (_sharedDictionaries == null)
                _sharedDictionaries = new Dictionary<string, ResourceDictionary>();

            if (_sharedDictionaries.ContainsKey(uriString))
                return _sharedDictionaries[uriString];

            Uri resourceLocater = new Uri(uriString, UriKind.Relative);
            ResourceDictionary resource = (ResourceDictionary)Application.LoadComponent(resourceLocater);
            _sharedDictionaries.Add(uriString, resource);

            return resource;
        }
    }
}
